clear
import excel "INSERT FILE NAME"
cd "SET LOCATION"


//Author:Jack Mewhirter
//Date: 8/12/2025
//Contact: jmewhirt@utk.edu
//NOTE--this file shows how to replicate file from raw data for full transparency. Sorry for the messiness of the raw file :)
//Feel free to reach out if you have any questions or concerns. 





**SECTION 1: ATTENTION CHECK** --varname=correct
encode Inaprevioussectionyouwere, gen(test)
encode FL_41BlockRandomizerDispl, gen(answer)
tab test
tab answer
gen correct=0
replace correct=1 if test==3 & answer==1
replace correct=1 if test==4 & answer==2
tab correct










**SECTION 2: POLICE OUTCOMES**

//SECTION 1a: GENERAL PERCEPTIONS: varnames= police_outcome1- police_outcome6 + police_outcome_scale
tab Pleasecarefullyreviewthepoli
encode Pleasecarefullyreviewthepoli, gen(po1)
tab po1
gen police_outcome1=. 
replace police_outcome1=1 if po1==5
replace police_outcome1=2 if po1==2
replace police_outcome1=3 if po1==3
replace police_outcome1=4 if po1==1
replace police_outcome1=5 if po1==4


encode AB, gen(po2)
tab po2
gen police_outcome2=. 
replace police_outcome2=1 if po2==5
replace police_outcome2=2 if po2==2
replace police_outcome2=3 if po2==3
replace police_outcome2=4 if po2==1
replace police_outcome2=5 if po2==4

encode AC, gen(po3)
tab po3
gen police_outcome3=. 
replace police_outcome3=1 if po3==5
replace police_outcome3=2 if po3==2
replace police_outcome3=3 if po3==3
replace police_outcome3=4 if po3==1
replace police_outcome3=5 if po3==4

encode AD, gen(po4)
tab po4
gen police_outcome4=. 
replace police_outcome4=1 if po4==5
replace police_outcome4=2 if po4==2
replace police_outcome4=3 if po4==3
replace police_outcome4=4 if po4==1
replace police_outcome4=5 if po4==4

encode AE, gen(po5)
tab po5
gen police_outcome5=. 
replace police_outcome5=1 if po5==5
replace police_outcome5=2 if po5==2
replace police_outcome5=3 if po5==3
replace police_outcome5=4 if po5==1
replace police_outcome5=5 if po5==4

encode AF, gen(po6)
tab po6
gen police_outcome6=. 
replace police_outcome6=1 if po6==5
replace police_outcome6=2 if po6==2
replace police_outcome6=3 if po6==3
replace police_outcome6=4 if po6==1
replace police_outcome6=5 if po6==4

//scale
egen police_outcome_scale=rowmean(police_outcome1 police_outcome2 police_outcome3 police_outcome4 police_outcome5 police_outcome6)




//Section 1b: Police Coporudction: varnames= police_coproduce_cost + police_coproduce_nocost
tab AI 
encode AI, gen(pcam)
tab pcam
gen police_coproduce_cost=.
replace police_coproduce_cost=1 if pcam==5
replace police_coproduce_cost=2 if pcam==2
replace police_coproduce_cost=3 if pcam==3
replace police_coproduce_cost=4 if pcam==1
replace police_coproduce_cost=5 if pcam==4

tab Recentlythedepartmentdevelop //CAMERA
encode Recentlythedepartmentdevelop, gen(pcam2)
tab pcam
gen police_coproduce_nocost=.
replace police_coproduce_nocost=1 if pcam2==5
replace police_coproduce_nocost=2 if pcam2==2
replace police_coproduce_nocost=3 if pcam2==3
replace police_coproduce_nocost=4 if pcam2==1
replace police_coproduce_nocost=5 if pcam2==4










**SECTION 3: Water Outcomes

//SECTION 3a: GENERAL PERCEPTIONS: varnames= water_outcome1- water_outcome6 + water_outcome_scale
tab Pleasecarefullyreadthewater
encode Pleasecarefullyreadthewater, gen(wo1)
gen water_outcome1=.
replace water_outcome1=1 if wo1==5
replace water_outcome1=2 if wo1==2
replace water_outcome1=3 if wo1==3
replace water_outcome1=4 if wo1==1
replace water_outcome1=5 if wo1==4


encode AO, gen(wo2)
gen water_outcome2=.
replace water_outcome2=1 if wo2==5
replace water_outcome2=2 if wo2==2
replace water_outcome2=3 if wo2==3
replace water_outcome2=4 if wo2==1
replace water_outcome2=5 if wo2==4

encode AP, gen(wo3)
gen water_outcome3=.
replace water_outcome3=1 if wo3==5
replace water_outcome3=2 if wo3==2
replace water_outcome3=3 if wo3==3
replace water_outcome3=4 if wo3==1
replace water_outcome3=5 if wo3==4

encode AQ, gen(wo4)
gen water_outcome4=.
replace water_outcome4=1 if wo4==5
replace water_outcome4=2 if wo4==2
replace water_outcome4=3 if wo4==3
replace water_outcome4=4 if wo4==1
replace water_outcome4=5 if wo4==4

encode AR, gen(wo5)
gen water_outcome5=.
replace water_outcome5=1 if wo5==5
replace water_outcome5=2 if wo5==2
replace water_outcome5=3 if wo5==3
replace water_outcome5=4 if wo5==1
replace water_outcome5=5 if wo5==4

encode AS, gen(wo6)
gen water_outcome6=.
replace water_outcome6=1 if wo6==5
replace water_outcome6=2 if wo6==2
replace water_outcome6=3 if wo6==3
replace water_outcome6=4 if wo6==1
replace water_outcome6=5 if wo6==4


//scale
egen water_outcome_scale=rowmean(water_outcome1 water_outcome2 water_outcome3 water_outcome4 water_outcome5 water_outcome6)





//SECTION 3b: Coproduction: varnames= water_coproduce_cost + water_coproduce_nocost
encode AV, gen(wshower)
gen water_coproduce_cost=.
replace water_coproduce_cost=1 if wshower==5
replace water_coproduce_cost=2 if wshower==2
replace water_coproduce_cost=3 if wshower==3
replace water_coproduce_cost=4 if wshower==1
replace water_coproduce_cost=5 if wshower==4


tab Recentlythiswaterdepartment
encode Recentlythiswaterdepartment, gen(wshowera)
gen water_coproduce_nocost=.
replace water_coproduce_nocost=1 if wshowera==5
replace water_coproduce_nocost=2 if wshowera==2
replace water_coproduce_nocost=3 if wshowera==3
replace water_coproduce_nocost=4 if wshowera==1
replace water_coproduce_nocost=5 if wshowera==4











**SECTION 4: Police + Water Collaboration: varnames= police_collab + water_collab
encode F117, gen(pcol)
tab pcol
gen police_collab=.
replace police_collab=1 if pcol==1
replace police_collab=2 if pcol==2
replace police_collab=3 if pcol==5
replace police_collab=4 if pcol==4
replace police_collab=5 if pcol==3


encode F217, gen(wcol)
tab wcol
gen water_collab=.
replace water_collab=1 if wcol==1
replace water_collab=2 if wcol==2
replace water_collab=3 if wcol==5
replace water_collab=4 if wcol==4
replace water_collab=5 if wcol==3










//SECTION 5: POLICE AND WATER EFFECTIVENESS: varnames=police_effectiveness + water_effectiveness
encode F111, gen(peff)
tab peff
gen police_effectiveness=.
replace police_effectiveness=1 if peff==2
replace police_effectiveness=2 if peff==3
replace police_effectiveness=3 if peff==1


encode F211, gen(weff)
tab weff
gen water_effectiveness=.
replace water_effectiveness=1 if weff==2
replace water_effectiveness=2 if weff==3
replace water_effectiveness=3 if weff==1









//SECTION 6: POLICE AND WATER COMPLAINTS: varname=police_complaints + water_complaints
encode F112, gen(pcomps)
tab pcomps
gen police_complaints=.
replace police_complaints=1 if pcomps==2
replace police_complaints=2 if pcomps==3
replace police_complaints=3 if pcomps==1


encode F212, gen(wcomps)
tab wcomps
gen water_complaints=.
replace water_complaints=1 if wcomps==2
replace water_complaints=2 if wcomps==3
replace water_complaints=3 if wcomps==1







//SECTION 7: BUDGET
encode F113, gen(pbudg)
tab pbudg
gen police_budget=.
replace police_budget=1 if pbudg==2
replace police_budget=2 if pbudg==3
replace police_budget=3 if pbudg==1

encode F213, gen(wbudg)
tab wbudg
gen water_budget=.
replace water_budget=1 if wbudg==2
replace water_budget=2 if wbudg==3
replace water_budget=3 if wbudg==1









//SECTION 8: NW Population Served
encode F114, gen(pnwpop)
tab pnwpop
gen police_community_nw=.
replace police_community_nw=1 if pnwpop==2
replace police_community_nw=2 if pnwpop==3
replace police_community_nw=3 if pnwpop==1

encode F214, gen(wnwpop)
tab wnwpop
gen water_community_nw=.
replace water_community_nw=1 if wnwpop==2
replace water_community_nw=2 if wnwpop==3
replace water_community_nw=3 if wnwpop==1












//SECTION 9: NW SLBs
encode F115, gen(pnw)
tab pnw
gen police_slb_nw=.
replace police_slb_nw=1 if pnw==2
replace police_slb_nw=2 if pnw==3
replace police_slb_nw=3 if pnw==1

encode F215, gen(wnw)
tab wnw
gen water_slb_nw=.
replace water_slb_nw=1 if wnw==2
replace water_slb_nw=2 if wnw==3
replace water_slb_nw=3 if wnw==1











//SECTION 10: Female SLBs
encode F116, gen(pfem)
tab pfem
gen police_slb_fem=.
replace police_slb_fem=1 if pfem==2
replace police_slb_fem=2 if pfem==3
replace police_slb_fem=3 if pfem==1

encode F216, gen(wfem)
tab wfem
gen water_slb_fem=.
replace water_slb_fem=1 if wfem==2
replace water_slb_fem=2 if wfem==3
replace water_slb_fem=3 if wfem==1






//ASSESS SAMPLE SIZE
gen sample=.
replace sample=1 if police_collab<3   & FL_41BlockRandomizerDispl=="PoliceRC"
replace sample=1 if water_collab<3   & FL_41BlockRandomizerDispl=="WaterRC"















**ANALYSIS
**TEST 1: MARGINAL MEAN TESTS

//TEST 1a: MARGINAL MEAN TEST POLICE
mean police_outcome_scale if  FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 //  3.309313

mean police_outcome_scale if police_effectiveness==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe1
mean police_outcome_scale if police_effectiveness==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe2
mean police_outcome_scale if police_effectiveness==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe3

mean police_outcome_scale if police_complaints==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc1
mean police_outcome_scale if police_complaints==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc2
mean police_outcome_scale if police_complaints==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc3

mean police_outcome_scale if police_budget==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb1
mean police_outcome_scale if police_budget==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb2
mean police_outcome_scale if police_budget==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb3

mean police_outcome_scale if police_community_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw1
mean police_outcome_scale if police_community_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw2
mean police_outcome_scale if police_community_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw3

mean police_outcome_scale if police_slb_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw1
mean police_outcome_scale if police_slb_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw2
mean police_outcome_scale if police_slb_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw3

mean police_outcome_scale if police_slb_fem==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf1
mean police_outcome_scale if police_slb_fem==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf2
mean police_outcome_scale if police_slb_fem==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf3

mean police_outcome_scale if police_collab==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol1
mean police_outcome_scale if police_collab==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol2

coefplot pcol1 pcol2 pe1 pe2 pe3 pc1 pc2 pc3 pb1 pb2 pb3  pcnw1 pcnw2 pcnw3 pnw1 pnw2 pnw3 pf1 pf2 pf3 , xline( 3.309313 ) 



//TEST 1b: MARGINAL MEAN TEST WATER
mean water_outcome_scale if  FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 //  3.315519

mean water_outcome_scale if water_effectiveness==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we1
mean water_outcome_scale if water_effectiveness==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we2
mean water_outcome_scale if water_effectiveness==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we3

mean water_outcome_scale if water_complaints==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc1
mean water_outcome_scale if water_complaints==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc2
mean water_outcome_scale if water_complaints==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc3

mean water_outcome_scale if water_budget==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb1
mean water_outcome_scale if water_budget==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb2
mean water_outcome_scale if water_budget==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb3

mean water_outcome_scale if water_community_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw1
mean water_outcome_scale if water_community_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw2
mean water_outcome_scale if water_community_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw3

mean water_outcome_scale if water_slb_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw1
mean water_outcome_scale if water_slb_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw2
mean water_outcome_scale if water_slb_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw3

mean water_outcome_scale if water_slb_fem==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf1
mean water_outcome_scale if water_slb_fem==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf2
mean water_outcome_scale if water_slb_fem==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf3

mean water_outcome_scale if water_collab==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol1
mean water_outcome_scale if water_collab==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol2

coefplot wcol1 wcol2 we1 we2 we3 wc1 wc2 wc3 wb1 wb2 wb3  wcnw1 wcnw2 wcnw3 wnw1 wnw2 wnw3 wf1 wf2 wf3 , xline( 3.315519 )
















//APPENDIX




//SECTION 1:  ASSESSING DV RELIABILITY AND CONSIDERING AN ALTERNATE SCALE (FACTOR ANALYSIS)
//TABLES A1-A4 + FIGURES A1-A2



//test reliability: .7 IIC, .9 SR
alpha police_outcome1 police_outcome2 police_outcome3 police_outcome4 police_outcome5 police_outcome6 if  FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3

alpha water_outcome1 water_outcome2 water_outcome3 water_outcome4 water_outcome5 water_outcome6  if  FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3

//FACTOR LOADING
factor police_outcome1 police_outcome2 police_outcome3 police_outcome4 police_outcome5 police_outcome6 if  FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3
predict factorp

factor water_outcome1 water_outcome2 water_outcome3 water_outcome4 water_outcome5 water_outcome6  if  FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3
predict factorw


//WATER TEST: ALT DV
mean factorw if  FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 //  3.315519

mean factorw if water_effectiveness==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we1a
mean factorw if water_effectiveness==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we2a
mean factorw if water_effectiveness==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we3a

mean factorw if water_complaints==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc1a
mean factorw if water_complaints==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc2a
mean factorw if water_complaints==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc3a

mean factorw if water_budget==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb1a
mean factorw if water_budget==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb2a
mean factorw if water_budget==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb3a

mean factorw if water_community_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw1a
mean factorw if water_community_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw2a
mean factorw if water_community_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw3a

mean factorw if water_slb_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw1a
mean factorw if water_slb_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw2a
mean factorw if water_slb_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw3a

mean factorw if water_slb_fem==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf1a
mean factorw if water_slb_fem==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf2a
mean factorw if water_slb_fem==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf3a

mean factorw if water_collab==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol1a
mean factorw if water_collab==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol2a

coefplot wcol1a wcol2a we1a we2a we3a wc1a wc2a wc3a wb1a wb2a wb3a  wcnw1a wcnw2a wcnw3a wnw1a wnw2a wnw3a wf1a wf2a wf3a , xline( -1.08e-09 )



//POLICE AT TESTS
mean factorp if  FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 //  3.309313

mean factorp if police_effectiveness==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe1a
mean factorp if police_effectiveness==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe2a
mean factorp if police_effectiveness==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe3a

mean factorp if police_complaints==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc1a
mean factorp if police_complaints==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc2a
mean factorp if police_complaints==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc3a

mean factorp if police_budget==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb1a
mean factorp if police_budget==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb2a
mean factorp if police_budget==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb3a

mean factorp if police_community_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw1a
mean factorp if police_community_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw2a
mean factorp if police_community_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw3a

mean factorp if police_slb_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw1a
mean factorp if police_slb_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw2a
mean factorp if police_slb_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw3a

mean factorp if police_slb_fem==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf1a
mean factorp if police_slb_fem==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf2a
mean factorp if police_slb_fem==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf3a

mean factorp if police_collab==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol1a
mean factorp if police_collab==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol2a

coefplot pcol1a pcol2a pe1a pe2a pe3a pc1a pc2a pc3a pb1a pb2a pb3a  pcnw1a pcnw2a pcnw3a pnw1a pnw2a pnw3a pf1a pf2a pf3a , xline( -4.31e-10 )










//SECTION 2: ASSESSING RANDOMIZATION OF ATTRIBUTE VALUES
//TABLE 5 + FIGURES A5-A10
//NOTE: SEE ALT .DO FILE FOR FIGS A3-A4



//COVARS: GENDER, RACE, LATINO: MALE; RACE; PARTY;  AGE

encode Whichbestdescribesyourgender, gen(gender)
gen male=0
replace male=1 if gender==2


gen id=_n
encode Chooseoneormoreracesthatyo, gen(race_long)
list id if race_long==3

gen race=.
replace race=0 if Chooseoneormoreracesthatyo=="White or Caucasian"
replace race=1 if Chooseoneormoreracesthatyo=="Black or African American"
replace race=2 if race_long<5 //asian 
replace race=3 if race_long==17 //other
recode race .=4 if race_long!=. //mixed

encode WouldyoudescribeyourselfasH, gen(latin_long)
gen latin=0
replace latin=1 if latin_long==2
 
encode Generallyspeakingdoyouusual, gen(party)
recode party 5=3 //other


gen region=.
replace region=1 if Inwhichstatedoyoucurrently=="Connecticut" 
replace region=1 if Inwhichstatedoyoucurrently=="Maine" 
replace region=1 if Inwhichstatedoyoucurrently=="Massachusetts" 
replace region=1 if Inwhichstatedoyoucurrently=="New Hampshire" 
replace region=1 if Inwhichstatedoyoucurrently=="Rhode Island" 
replace region=1 if Inwhichstatedoyoucurrently=="Vermont" 
replace region=1 if Inwhichstatedoyoucurrently=="New Jersey" 
replace region=1 if Inwhichstatedoyoucurrently=="New York" 
replace region=1 if Inwhichstatedoyoucurrently=="Pennsylvania" 

replace region=2 if Inwhichstatedoyoucurrently=="Illinois" 
replace region=2 if Inwhichstatedoyoucurrently=="Indiana" 
replace region=2 if Inwhichstatedoyoucurrently=="Michigan" 
replace region=2 if Inwhichstatedoyoucurrently=="Ohio" 
replace region=2 if Inwhichstatedoyoucurrently=="Wisconsin" 
replace region=2 if Inwhichstatedoyoucurrently=="Iowa" 
replace region=2 if Inwhichstatedoyoucurrently=="Kansas" 
replace region=2 if Inwhichstatedoyoucurrently=="Minnesota" 
replace region=2 if Inwhichstatedoyoucurrently=="Missouri" 
replace region=2 if Inwhichstatedoyoucurrently=="Nebraska" 
replace region=2 if Inwhichstatedoyoucurrently=="North Dakota" 
replace region=2 if Inwhichstatedoyoucurrently=="South Dakota"

replace region=3 if Inwhichstatedoyoucurrently=="Delaware" 
replace region=3 if Inwhichstatedoyoucurrently=="Florida" 
replace region=3 if Inwhichstatedoyoucurrently=="Georgia" 
replace region=3 if Inwhichstatedoyoucurrently=="Maryland" 
replace region=3 if Inwhichstatedoyoucurrently=="North Carolina" 
replace region=3 if Inwhichstatedoyoucurrently=="South Carolina" 
replace region=3 if Inwhichstatedoyoucurrently=="Virginia" 
replace region=3 if Inwhichstatedoyoucurrently=="Washington, D.C." 
replace region=3 if Inwhichstatedoyoucurrently=="West Virginia" 
replace region=3 if Inwhichstatedoyoucurrently=="Alabama" 
replace region=3 if Inwhichstatedoyoucurrently=="Kentucky" 
replace region=3 if Inwhichstatedoyoucurrently=="Mississippi"
replace region=3 if Inwhichstatedoyoucurrently=="Tennessee" 
replace region=3 if Inwhichstatedoyoucurrently=="Arkansas" 
replace region=3 if Inwhichstatedoyoucurrently=="Louisiana" 
replace region=3 if Inwhichstatedoyoucurrently=="Oklahoma" 
replace region=3 if Inwhichstatedoyoucurrently=="Texas"

replace region=4 if Inwhichstatedoyoucurrently=="Arizona" 
replace region=4 if Inwhichstatedoyoucurrently=="Colorado" 
replace region=4 if Inwhichstatedoyoucurrently=="Idaho" 
replace region=4 if Inwhichstatedoyoucurrently=="Montana"
replace region=4 if Inwhichstatedoyoucurrently=="New Mexico" 
replace region=4 if Inwhichstatedoyoucurrently=="Utah" 
replace region=4 if Inwhichstatedoyoucurrently=="Wyoming" 
replace region=4 if Inwhichstatedoyoucurrently=="Alaska" 
replace region=4 if Inwhichstatedoyoucurrently=="California"
replace region=4 if Inwhichstatedoyoucurrently=="Hawaii"
replace region=4 if Inwhichstatedoyoucurrently=="Oregon" 
replace region=4 if Inwhichstatedoyoucurrently=="Washington" 
replace region=4 if Inwhichstatedoyoucurrently=="Nevada" 

rename  Whatisyourcurrentage age
destring age, replace 

encode Whatwasyourtotalhouseholdin, gen(hhinc)
sum hhinc
gen hh_income=0
replace hh_income=1 if hhinc==3
replace hh_income=2 if hhinc==4
replace hh_income=5 if hhinc==5
replace hh_income=6 if hhinc==1
replace hh_income=7 if hhinc==2





//BALANCE TEST POLICE 
mlogit police_effectiveness male i.race latin i.region age hh_income i.party if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2) //1/28
margins, dydx(*) predict(outcome(1) xb)  
est sto pol1a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol1c 

mlogit police_complaints  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2) //2
margins, dydx(*) predict(outcome(1) xb)  
est sto pol2a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol2c 

mlogit police_budget  male i.race latin i.region age hh_income  i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2) //2
margins, dydx(*) predict(outcome(1) xb)  
est sto pol3a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol3c 

mlogit police_community_nw  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2)  //0
margins, dydx(*) predict(outcome(1) xb)  
est sto pol4a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol4c 

mlogit police_slb_nw  male i.race latin i.region age hh_income  i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2)  //2
margins, dydx(*) predict(outcome(1) xb)   
est sto pol5a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol5c 

mlogit police_slb_fem  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3, base(2) //1
margins, dydx(*) predict(outcome(1) xb)  
est sto pol6a
margins, dydx(*) predict(outcome(3) xb) post
est sto pol6c 


gen police_collab2=police_collab-1
logit police_collab2 male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3  //0
est sto pol7c 


set scheme plotplain
coefplot pol1a pol2a pol3a pol4a pol5a pol6a, drop(_cons) xline(0)
coefplot pol1c pol2c pol3c pol4c pol5c pol6c pol7c, drop(_cons) xline(0)


//WATER BALANCE TESTS
mlogit water_effectiveness male i.race latin i.region age hh_income i.party if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2) //1
margins, dydx(*) predict(outcome(1) xb)  
est sto wat1a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat1c 

mlogit water_complaints  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2)  //1
margins, dydx(*) predict(outcome(1) xb)  
est sto wat2a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat2c 

mlogit water_budget  male i.race latin i.region age hh_income  i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2) //2
margins, dydx(*) predict(outcome(1) xb)  
est sto wat3a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat3c 

mlogit water_community_nw  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2)  //1
margins, dydx(*) predict(outcome(1) xb)  
est sto wat4a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat4c 

mlogit water_slb_nw  male i.race latin i.region age hh_income  i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2) //0
margins, dydx(*) predict(outcome(1) xb)  
est sto wat5a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat5c 

mlogit water_slb_fem  male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3, base(2)  //1
margins, dydx(*) predict(outcome(1) xb)  
est sto wat6a
margins, dydx(*) predict(outcome(3) xb) post
est sto wat6c 

gen water_collab2=water_collab-1
logit water_collab2 male i.race latin i.region age hh_income i.party  if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & police_collab<3  //1   =16 total = 4.395604%
est sto wat7c 


set scheme plotplain
coefplot wat1a wat2a wat3a wat4a wat5a wat6a , drop(_cons) xline(0)
coefplot wat1c wat2c wat3c wat4c wat5c wat6c wat7c, drop(_cons) xline(0)





//Testing and Adjusting for Non Representativeness through Raking
gen keepers=. 
replace keepers=1 if FL_41BlockRandomizerDispl=="WaterRC" & correct==1  & water_collab<3 
replace keepers=1 if FL_41BlockRandomizerDispl=="PoliceRC" & correct==1  & police_collab<3 


tab male if keepers==1
tab race if keepers==1
tab latin if keepers==1
tab region if keepers==1
sum age 
tab hh_income if keepers==1 
tab party  if keepers==1


gen age_tab=.
replace age_tab=1 if age>17
replace age_tab=2 if age>24
replace age_tab=3 if age>44
replace age_tab=4 if age>64

tab age_tab



encode ResponseID, gen(response_id)
drop if response_id==.
drop if keepers==.

rename race race_x
set seed 123
svycal rake i.male i.latin i.hh_income i.race_x i.age_tab i.region i.party, ll(0.1) ul(100) iterate(10000) gen(rake_wt_final101) totals( ///
_cons=3488  ///
0.male= 1762 ///
1.male= 1726       ///
0.latin= 2835   ///
1.latin= 653   ///
0.hh_income=598   ///
1.hh_income=695   ///
2.hh_income=577   ///
5.hh_income=423   ///
6.hh_income=576   ///
7.hh_income=619  ///
0.race_x=2147   ///
1.race_x=432   ///
2.race_x=212   ///
3.race_x=292   ///
4.race_x=355   ///
1.age_tab= 388  ///
2.age_tab= 1095  ///
3.age_tab= 1070  ///
4.age_tab= 935  ///
1.region= 597  ///
2.region= 724  ///
3.region= 1337  ///
4.region= 830 ///      
1.party= 1081  ///
2.party= 1430 ///
3.party= 140  ///
4.party= 837) 




svyset ResponseID [pweight=rake_wt_final101]
svy: tab race_x, count
svy: tab male, count
svy: tab latin, count
svy: tab hh_income, count
svy: tab region, count
svy: tab age_tab, count
svy: tab party, count




//MEANS TEST with Raked
svy: mean police_outcome_scale if  FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 //  3.324569 

svy: mean police_outcome_scale if police_effectiveness==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe1b
svy: mean police_outcome_scale if police_effectiveness==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe2b
svy: mean police_outcome_scale if police_effectiveness==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pe3b

svy: mean police_outcome_scale if police_complaints==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc1b
svy: mean police_outcome_scale if police_complaints==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc2b
svy: mean police_outcome_scale if police_complaints==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pc3b

svy: mean police_outcome_scale if police_budget==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb1b
svy: mean police_outcome_scale if police_budget==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb2b
svy: mean police_outcome_scale if police_budget==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pb3b

svy: mean police_outcome_scale if police_community_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw1b
svy: mean police_outcome_scale if police_community_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw2b
svy: mean police_outcome_scale if police_community_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcnw3b

svy: mean police_outcome_scale if police_slb_nw==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw1b
svy: mean police_outcome_scale if police_slb_nw==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw2b
svy: mean police_outcome_scale if police_slb_nw==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pnw3b

svy: mean police_outcome_scale if police_slb_fem==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf1b
svy: mean police_outcome_scale if police_slb_fem==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf2b
svy: mean police_outcome_scale if police_slb_fem==3 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pf3b

svy: mean police_outcome_scale if police_collab==1 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol1b
svy: mean police_outcome_scale if police_collab==2 & FL_41BlockRandomizerDispl=="PoliceRC" & correct==1 & police_collab<3 
estimates store pcol2b

coefplot pcol1b pcol2b pe1b pe2b pe3b pc1b pc2b pc3b pb1b pb2b pb3b  pcnw1b pcnw2b pcnw3b pnw1b pnw2b pnw3b pf1b pf2b pf3b , xline( 3.324569  )



//TEST 1b: MARGINAL MEAN TEST WATER
svy: mean water_outcome_scale if  FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 //  3.313341

svy: mean water_outcome_scale if water_effectiveness==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we1b
svy: mean water_outcome_scale if water_effectiveness==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we2b
svy: mean water_outcome_scale if water_effectiveness==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store we3b

svy: mean water_outcome_scale if water_complaints==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc1b
svy: mean water_outcome_scale if water_complaints==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc2b
svy: mean water_outcome_scale if water_complaints==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wc3b

svy: mean water_outcome_scale if water_budget==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb1b
svy: mean water_outcome_scale if water_budget==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb2b
svy: mean water_outcome_scale if water_budget==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wb3b

svy: mean water_outcome_scale if water_community_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw1b
svy: mean water_outcome_scale if water_community_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw2b
svy: mean water_outcome_scale if water_community_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcnw3b

svy: mean water_outcome_scale if water_slb_nw==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw1b
svy: mean water_outcome_scale if water_slb_nw==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw2b
svy: mean water_outcome_scale if water_slb_nw==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wnw3b

svy: mean water_outcome_scale if water_slb_fem==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf1b
svy: mean water_outcome_scale if water_slb_fem==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf2b
svy: mean water_outcome_scale if water_slb_fem==3 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wf3b

svy: mean water_outcome_scale if water_collab==1 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol1b
svy: mean water_outcome_scale if water_collab==2 & FL_41BlockRandomizerDispl=="WaterRC" & correct==1 & water_collab<3 
estimates store wcol2b

coefplot wcol1b wcol2b we1b we2b we3b wc1b wc2b wc3b wb1b wb2b wb3b  wcnw1b wcnw2b wcnw3b wnw1b wnw2b wnw3b wf1b wf2b wf3b , xline( 3.313341 )








